﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RangeValidator2.MaximumValue = DateTime.Now.ToShortDateString();
        }

        protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            if (args.Value == "admin")
            {
                args.IsValid = false;
            }
            else
            {
                args.IsValid = true;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (CompareValidator1.IsValid == false)
            {
                Response.Write("<script>('用户名不能admin')</script>");
            }
            if (ful.HasFile)
            {
                string filename = ful.FileName;
                if (filename.EndsWith(".jpg") || filename.EndsWith(".png") || filename.EndsWith("gif"))
                {
                    string url = Server.MapPath(@"~\img\") + filename;
                    ful.SaveAs(url);
                    Image1.ImageUrl = @"~\img\" + filename;
                    Image1.Visible = true;
                }
                else
                {
                    CustomValidator2.ErrorMessage = "格式不对，格式只能是jpg,png,gif";
                    CustomValidator2.IsValid = false;
                    Response.Write("<script>('格式不对，格式只能是jpg,png,gif')</script>");
                    return;
                }
            }
            else
            {
                CustomValidator2.ErrorMessage = "不能上传空文件";
                CustomValidator2.IsValid = false;
                Response.Write("<script>('不能上传空文件')</script>");
                return;
            }
            if (Page.IsValid == true)
            {
                Literal1.Text = "注册成功     <a href = '/WebForm2.aspx'>点及此处跳转到登录页面</a>";
            }
        }
    }
}